<template>
  <div>
    <van-nav-bar title="评论" fixed left-arrow @click-left="$router.back()" />
    <div class="main">
      <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
        <div class="wrap" v-for="(obj, index) in list" :key="index">
          <div class="img_wrap">
            <img style="width: 30px; border-radius: 30px;" :src="obj.user.avatarUrl" alt="">
          </div>
          <div class="content_wrap">
            <div class="header_wrap">
              <div class="info_wrap">
                <p>{{ obj.user.nickname }}</p>
              </div>
              <div @click="">{{ obj.likedCount }}点赞</div>
            </div>
            <div class="footer_wrap">
              <p>{{ obj.content }}</p>
            </div>
          </div>
        </div>
      </van-pull-refresh>
    </div>
  </div>
</template>

<style scoped>
.main {
  width: 95%;
  margin-top: 50px;
  margin-left: 2.5%;
}

.wrap {
  margin-top: 30px;
  max-height: 200px;
  display: flex;
  /* border-bottom: 1px solid #c4bebe; */
}

.content_wrap {
  width: 90%;
  margin-left: 10px;
  margin-bottom: 5px;
  /* border: 1px solid #000; */
}

.header_wrap {
  display: flex;
  justify-content: space-between;
  /* border: 1px solid #000; */
}

.info_wrap {
  font-size: 15px;
}

.footer_wrap {
  margin-top: 10px;
  font-size: 12px;
}
</style>

<script>
import { getCommentListByIdAPI } from '@/api';
export default {
  data() {
    return {
      list: [],
      isLoading: false, //加载完毕
      likedCount:0
    }
  },
  methods: {
    async onRefresh() {
      this.list = []
      this.getList()
    },
    async getList() {
      const res = await getCommentListByIdAPI({
        id: this.$route.query.id,
        limit: 20
      })
      this.list = res.data.comments,
      this.likedCount = res.data.comments.likedCount
      this.isLoading = false
      console.log(res);
    },
  },

  created() {
    this.getList()
  }
}
</script>